neighbors_dir = '/autofs/space/clive_001/users/adriana/GE_SVM/GE_grand_average_results/neighbors/20220516-0910/';

neighbors_result_files = dir([neighbors_dir, '*.mat']);


ROIs = {'R-LOC_1', 'R-ParsOrb_1', 'R-SFG_2', 'R-SFG_3', 'R-SFG_1', 'R-preCG_2',...
    'R-preCG_1', 'R-postCG_2', 'R-postCG_4', 'R-postCG_3', 'R-postCG_1', 'R-postCG_5', 'R-AG_1',...
    'R-ITG_2', 'R-ITG_1', 'R-ITG_3', 'R-MTG_4', 'R-MTG_2', 'R-MTG_1', 'R-MTG_3', 'R-STG_2', 'R-STG_3', 'R-STG_1',...
    'L-CC_1', 'L-ParaHip_1', 'L-ParsOrb_1', 'L-ParsTri_1', 'L-cMFG_1', 'L-SFG_1', 'L-postCG_1', 'L-SMG_1',...
    'L-SPC_1', 'L-ITG_2', 'L-ITG_1', 'L-TPol_1', 'L-MTG_1', 'L-MTG_2', 'L-STG_2', 'L-STG_1'};

pubROIs = {'R-LOC_1', 'R-ParsOrb_1', 'R-SFG_3', 'R-SFG_2', 'R-SFG_1', 'R-preCG_2',...
    'R-preCG_1', 'R-postCG_5', 'R-postCG_4', 'R-postCG_3', 'R-postCG_2', 'R-postCG_1', 'R-AG_1',...
    'R-ITG_3', 'R-ITG_2', 'R-ITG_1', 'R-MTG_4', 'R-MTG_3', 'R-MTG_2', 'R-MTG_1', 'R-STG_3', 'R-STG_2', 'R-STG_1',...
    'L-CC_1', 'L-ParaHip_1', 'L-ParsOrb_1', 'L-ParsTri_1', 'L-cMFG_1', 'L-SFG_1', 'L-postCG_1', 'L-SMG_1',...
    'L-SPC_1', 'L-ITG_2', 'L-ITG_1', 'L-TPol_1', 'L-MTG_2', 'L-MTG_1', 'L-STG_2', 'L-STG_1'};

time = -100:1000;
ndecoders = 0;
figure('Position', [986, 340, 558, 572]);
for kfile = 1:length(neighbors_result_files)
    file = neighbors_result_files(kfile);
    load(fullfile(neighbors_dir,file.name));
    if ~isempty(stat_ave.clusters)
        fnameparts = split(file.name, {'_', '-'});
        roiname = sprintf('%s-%s_%s', fnameparts{3}, fnameparts{4}, fnameparts{5});
        ndecoders = find(ismember(ROIs, roiname));
        if ~isempty(ndecoders)
            for kcluster = 1:length(stat_ave.clusters)
                timestart = time(stat_ave.clusters{kcluster}(1));
                timeend = time(stat_ave.clusters{kcluster}(end));
                plot([timestart, timeend], [ndecoders, ndecoders], 'k|-'); hold on;
            end
        end
    end
end
set(gca, 'TickLabelInterpreter', 'none');
set(gca, 'YLim', [0, length(ROIs)+1], 'YTick', 1:length(ROIs), 'YTickLabels', pubROIs);
set(gca, 'XLim', [-100, 1000]);
xlabel('Time (ms)');
area([0, 350], [length(ROIs)+1; length(ROIs)+1], 'FaceColor', [0.75, 0.75, 0.75], 'FaceAlpha', 0.25);